<template>
    <div class="goodslist">
        <myheader title="商品列表"></myheader>
        <div class="list-wrap">
            <div class="list-item" v-for="item in goodslist" :key="item.id" @click="goToGoodsinfo(item.id)">
                <img :src="item.img_url" alt="这是个商品图片，图片跑丢了！">
                <div class="item-title">
                    <h4>{{item.title}}</h4>
                    <p class="subtitle">
                       {{item.zhaiyao}}
                    </p>
                </div>
                <div class="item-info">
                    <span class="card">50天历史最低价</span>
                    <p class="price">
                        <span class="now">{{item.sell_price | priceFormat}}</span>
                        <del>{{item.market_price | priceFormat}}</del>
                    </p>
                    <p class="hots">
                        <span class="hot">热卖中</span>
                        <span>剩余{{item.stock_quantity}}件</span>
                    </p>
                </div>
            </div>
            <mt-button plain size="large" type="primary" @click="getmMoreGoods">加载更多</mt-button>
        </div>
    </div>
</template>

<script>
    import myheader from '../../components/header'
    export default {
        name: "googslist",
        components:{
            myheader
        },
        data(){
            return {
                pageindex: 1,
                goodslist:[]
            }
        },
        methods:{
            getGoodsList(){ //获取商品列表数据
                this.$http.get('api/getgoods?pageindex='+this.pageindex).then(res=>{
                    console.log(res);
                    this.goodslist = this.goodslist.concat(res.body.message)
                },err=>{

                })
            },
            getmMoreGoods(){ //获取更多商品，
                this.pageindex++;
                this.getGoodsList()
            },
            goToGoodsinfo(goodsid){ //使用编程式导航，跳转到商品详情页的方法
                this.$router.push({name:'info',params:{id:goodsid}})
            }
        },
        created(){
            this.getGoodsList()
        }
    }
</script>

<style scoped lang="scss">
.list-wrap{
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 0 12px 55px;
    .list-item{
        width: 48%;
        height: 345px;
        box-shadow: 0 0 6px rgba(0,0,0,.3);
        margin-top: 12px;
        padding: 8px;
        position: relative;
        img{
            display: block;
            margin: auto;
            width: 85%;
        }
        .item-title{
            position: absolute;
            width: 91%;
            bottom: 100px;
            h4{
                font-size: 14px;
                font-weight: 400;
                overflow: hidden;
                text-overflow:ellipsis;
                white-space: nowrap;
            }
            .subtitle{
                color: red;
                font-size: 12px;
            }
        }
        .item-info{
            border-top: 1px solid #eeeeee;
            padding-top: 5px;
            position: absolute;
            bottom: 0;
            width: 91%;
            height: 100px;
            .card{
                background-color: #e5e5e5;
                font-size: 10px;
                padding: 5px;
                border-radius: 6px;
                color: #777777;
            }
            .price{
                margin: 8px 0;
                span{
                    margin-right: 6px;
                }
                .now{
                    color: red;
                    font-size: 18px;
                }
            }
            .hots{
                margin: 8px 0 0;
                display: flex;
                justify-content: space-between;
                .hot{
                    border: red solid 2px;
                    padding: 0 6px;
                    border-radius: 6px;
                    color: red;
                }
            }
        }
    }
    .mint-button--primary.is-plain{
        margin-top: 10px;
    }
}
</style>
